/* eslint-disable no-unused-vars */
import namespace from "../../namespace";
import ArrayList from "../../util/ArrayList";
/**
 * 拖拽共有行为
 */
class DragDropPolicy extends namespace.policy.Policy {
  constructor() {
    super();
  }

  /**
   * 图形 元素
   * @param {*} element
   */
  onInstall(figure) {
    this.figure = figure;
  }

  /**
   * 元素
   * @param {*} element
   */
  onUninstall(canvas, figure) {
    this.figure.selectionHandles.each((i, f) => f.hide());
    this.figure.selectionHandles = new ArrayList();
    this.figure = null;
  }

  onDragStart(canvas, figure, x, y) {
    figure.shape.attr({ cursor: "move" });
    if (figure.isMoving === true) {
      figure.setAlpha(figure.originalAlpha);
    }
    figure.originalAlpha = figure.getAlpha();
    figure.isMoving = false;
  }

  onDrag(canvas, figure, dx, dy, dx2, dy2, event) {
    if (figure.isMoving === false) {
      figure.isMoving = true;
      figure.setAlpha(figure.originalAlpha * 0.4);
    }
  }

  onDragEnd(canvas, figure) {
    figure.shape.attr({ cursor: "default" });
    figure.isMoving = false;
    figure.setAlpha(figure.originalAlpha);
  }

  /**
   * 图形移动/后期尝试更换为订阅制
   */
  move(canvas, figure) { }

  adjustPosition(figure, x, y) {
    if (x instanceof namespace.geo.Point) {
      return x;
    }

    return new namespace.geo.Point(x, y);
  }
}

namespace.policy.figure.DragDropPolicy = DragDropPolicy;
